package com.qlk.odcinterface.manager.impl;

import java.util.List;

import com.qlk.common.manager.BaseManager;
import com.qlk.common.utils.page.PageUtil;
import com.qlk.odcinterface.domain.PmsChannels;
import com.qlk.odcinterface.domain.query.PmsChannelsQuery;
import com.qlk.odcinterface.dao.PmsChannelsDao;
import com.qlk.odcinterface.manager.PmsChannelsManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * PmsChannelsManager接口的实现类
 * 
 * @author zhaoyanan
 * @version 2016-4-14 13:22:58
 * 
 */
@Component
public class PmsChannelsManagerImpl extends BaseManager implements PmsChannelsManager {
	
    @Autowired
    private PmsChannelsDao pmsChannelsDao;

    /**
     * {@inheritDoc}
     */
    public boolean insert(final List<PmsChannels> pmsChannelsList) {
        boolean resultFlag = false;
        if (null != pmsChannelsList && pmsChannelsList.size() > 0) {
            for (PmsChannels pmsChannels : pmsChannelsList) {
                resultFlag = pmsChannelsDao.insert(pmsChannels);
                if (!resultFlag) {
                    throw new RuntimeException("批量新增表信息异常");
                }
            }
        }

        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    public boolean insert(PmsChannels pmsChannels) {
        return pmsChannelsDao.insert(pmsChannels);
    }

    /**
     * {@inheritDoc}
     */
    public boolean update(final PmsChannels pmsChannels) {
        return pmsChannelsDao.update(pmsChannels);
    }

    /**
     * {@inheritDoc}
     */
    public List<PmsChannels> queryPmsChannelsList(PmsChannelsQuery queryBean) {
        return pmsChannelsDao.queryPmsChannelsList(queryBean);
    }

    /**
     * {@inheritDoc}
     */
    public List<PmsChannels> queryPmsChannelsListWithPage(PmsChannelsQuery queryBean,
            PageUtil pageUtil) {
        if (null == queryBean) {
            queryBean = new PmsChannelsQuery();
        }

        // 查询总数
        int totalItem = queryPmsChannelsCount(queryBean);

        if (pageUtil == null) {
            pageUtil = new PageUtil();
        }
        pageUtil.setTotalRow(totalItem);
        pageUtil.init();
        
        if (totalItem > 0) {
            queryBean.setPageIndex(pageUtil.getCurPage());
            queryBean.setPageSize(pageUtil.getPageSize());
            // 调用Dao翻页方法
            return pmsChannelsDao.queryPmsChannelsListWithPage(queryBean);
        }
        return null;
    }

    /**
     * {@inheritDoc}
     */
    public int queryPmsChannelsCount(PmsChannelsQuery queryBean) {
        return pmsChannelsDao.queryPmsChannelsCount(queryBean);
    }

    /**
     * {@inheritDoc}
     */
    public boolean delete(PmsChannels pmsChannels) {
        return pmsChannelsDao.delete(pmsChannels);
    }

    /**
     * {@inheritDoc}
     */
    public PmsChannels getPmsChannelsById(Integer id) {
        return pmsChannelsDao.getPmsChannelsById(id);
    }

    /**
     * {@inheritDoc}
     */
    public boolean delete(final PmsChannels[] pmsChannelss) {
        boolean resultFlag = false;
        if (null != pmsChannelss && pmsChannelss.length > 0) {
            for (int i = 0; i < pmsChannelss.length; i++) {
                resultFlag = delete(pmsChannelss[i]);
                if (!resultFlag) {
                    throw new RuntimeException("批量删除表信息异常!");
                }
            }
        }

        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    public boolean exist(PmsChannels pmsChannels) {
        return pmsChannelsDao.exist(pmsChannels);
    }
}
